#
# This works, I just have to put the pieces back together, come back soon!
#
# tag_generic_table = Table('tag_generic', metadata,
#     Column('generic_id', Integer, primary_key=True),
#     Column('is_public', Boolean, default=True)
# )
# tag_localized_table = Table('tag_localized', metadata,
#     Column('localized_id', Integer, primary_key=True),
#     Column('tag_name', Unicode(200), nullable=True)
# )
# tag_table = Table('tag', metadata,
#     Column('revision_id', None, ForeignKey('revision.revision_id'), primary_key=True),
#     Column('content_id', None, ForeignKey('content.content_id')),
#     Column('tag_generic_id', None, ForeignKey('tag_generic.generic_id')),
#     Column('tag_localized_id', None, ForeignKey('tag_localized.localized_id'))
# )
# tagged_thing_table = Table('tagged_content', metadata,
#     Column('tagged_id', None, ForeignKey('revision.revision_id'), primary_key=True),
#     Column('page_id', None, ForeignKey('content.content_id')),
#     Column('tag_id', None, ForeignKey('content.content_id'))                         
# )
# 
# class Tag(Revision):
#     class Localized(LocalizedValues):
#         pass
#     class Generic(GenericValues):
#         pass
# 
#     def new_revision(self, _readonly_properties=None, _revisioned_onetoone_relations=None, **kwargs):
#         # Determine which properties *not* to copy over to a new instance
#         readonly_properties = []
#         if _readonly_properties: 
#             readonly_properties.extend(_readonly_properties)
#         # Specify which one_to_one relations should be revisioned
#         revisioned_onetoone_relations = ['_tag_localized', '_tag_generic']
#         if _revisioned_onetoone_relations:
#             revisioned_onetoone_relations.extend(_revisioned_onetoone_relations)
#         return super(Tag, self).new_revision(readonly_properties, revisioned_onetoone_relations, **kwargs)
#         
# 
# 
# mapper(Tag.Generic, tag_generic_table)
# mapper(Tag.Localized, tag_localized_table)
# mapper(Tag, tag_table, inherits=Revision, polymorphic_identity=u'tag')
# 
# class TaggedThing(Revision):
#     pass
# 
# mapper(TaggedThing, tagged_thing_table, inherits=Revision, polymorphic_identity=u'taggedthing',
#      properties={
#          'tag': relation(Tag, 
#              primaryjoin=and_(
#                  tagged_thing_table.c.tag_id==Tag.content_id,
#                  Tag.revision_id==select(
#                      [func.max(revision_table.c.revision_id)],
#                      group_by=revision_table.c.content_id,
#                      having=revision_table.c.content_id==tagged_thing_table.c.tag_id
#                  ).label('OOOOEEEEOO')
#              ),
#              foreign_keys=[tagged_thing_table.c.tag_id],
#              # backref=backref('_tagged_content', 
#              #     primaryjoin=Tag.content_id==tagged_thing_table.c.tag_id,
#              #     foreign_keys=[tagged_thing_table.c.tag_id]
#              # ),
#          ),
#          'thing': relation(Revision,
#              primaryjoin=and_(
#                  tagged_thing_table.c.thing_id==Revision.content_id,
#                  Revision.revision_id==select(
#                      [func.max(revision_table.c.revision_id)],
#                      group_by=revision_table.c.content_id,
#                      having=revision_table.c.content_id==tagged_thing_table.c.thing_id
#                  ).label('OHYEAH')
#              ),
#              foreign_keys=[tagged_thing_table.c.thing_id],
#              # backref=backref('_tags',
#              #     primaryjoin=Revision.content_id==tagged_thing_table.c.thing_id,
#              #     foreign_keys=[tagged_thing_table.c.thing_id]
#              # )
#          )
#      }
#  )